package main.java.design.memento;

/**
 * <p>
 * 负责创建一个备忘录，并且可以记录、恢复自身的内部状态。可以根据需要决定备忘录保存自身的那些内部状态。
 * </p>
 *
 * @author : wangdejian
 * @version 1.0
 * @date : 2020/6/25 19:16
 */
public class UserOriginator {

    private String username;
    private String passwd;

    // 创建一个备忘录
    public Memento createMemento() {
        return new Memento(username, passwd);
    }

    // 记录、恢复自身的内部状态
    public void restoreMemento(Memento memento) {
        this.passwd = memento.getPasswd();
        this.username = memento.getUsername();
    }


    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPasswd() {
        return passwd;
    }

    public void setPasswd(String passwd) {
        this.passwd = passwd;
    }

    public void show() {
        System.out.println("用户名:" + this.username);
        System.out.println("密码:" + this.passwd);
    }

}
